package com.ming.closeto.ui;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.Nullable;
import android.widget.TextView;

import com.ming.closeto.R;
import com.ming.closeto.base.BaseActivity;
import com.ming.closeto.utils.CacheSizeUtils;
import com.ming.closeto.view.CacheSanView;

public class CacheClearActivity extends BaseActivity {

    private CacheSanView mCacheSanView;

    private String cacheSize;
    private TextView tv_size;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_cache_clear);

        initView();
    }

    private void initView() {
        tv_size = findViewById(R.id.tv_size);
        cacheSize = CacheSizeUtils.getCacheSize(this);

        mCacheSanView = findViewById(R.id.mCacheSanView);
        tv_size.setText(CacheSizeUtils.getCacheSize(this));
        mCacheSanView.setAnimation(true);

        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                mCacheSanView.setAnimation(false);
                new AlertDialog.Builder(CacheClearActivity.this)
                        .setTitle("提示")
                        .setMessage("是否清理缓存？")
                        .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                CacheSizeUtils.clearAllCache(CacheClearActivity.this);
                                finish();
                            }
                        })
                        .setNegativeButton("取消", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                dialog.dismiss();
                                finish();
                            }
                        })
                        .show();
            }
        }, 1500);

    }
}
